import * as path  from "path";
import * as hx from "hbuilderx";
import { Counter } from "./counter";
import { Displayer } from "./displayer";
import notifier from "./notifier";

async function countAndDisplay(filePath: string) {
    let startTime = Date.now();
    let counter: Counter = new Counter(filePath);
    let displayer: Displayer = new Displayer(startTime, filePath, await counter.count());
    await displayer.display() == 1 ? countAndDisplay(filePath) : void 0;
}

export function activate(context: any) {
    notifier.activate(context);
    hx.vue.defineComponent("fileLinesCounterDisplayer", path.resolve(__dirname, "../static/fileLinesCounterDisplayer.vue"));
    
    context.subscriptions.push(hx.commands.registerCommand('count.file.lines', async (params: any) => {
        countAndDisplay(params.fsPath);
    }));
    context.subscriptions.push(hx.commands.registerCommand('count.dir.file.lines', async (params: any) => {
        countAndDisplay(params.fsPath);
    }));
}

export function deactivate() {
    notifier.deactivate();
}